<template>
  <view class="page">
    <view :style="{ height: statusBarHeight + 'px' }"></view>

    <view class="nav-bar">
      <view class="nav-left" @tap="goBack">
        <text class="fa fa-chevron-left fa-gray"></text>
      </view>
      <view class="nav-title">我的证书</view>
      <view class="nav-right" @tap="goToMessages">
        <text class="fa fa-bell-o search-icon fa-gray"></text>
      </view>
    </view>

    <view class="content">
      <view class="search-container">
        <view class="search-box">
          <text class="fa fa-search search-icon"></text>
          <input
            class="search-input"
            type="text"
            placeholder="搜索证书"
            v-model="searchKeyword"
          />
        </view>
      </view>

      <scroll-view scroll-y class="certificate-list">
        <!-- 证书1 - 已获得 -->
        <view class="certificate-card">
          <view class="certificate-info">
            <text class="certificate-title">住院医师规范化培训结业证书</text>
            <text class="certificate-type">类型：结业证书</text>
            <text class="certificate-date">颁发：2025.06.10 10:30</text>
            <text class="certificate-number">编号：IC-2025-0098</text>
            <view class="certificate-badge certificate-badge-green">
              <text class="certificate-badge-text">已获得</text>
            </view>
          </view>
          <view class="certificate-action" @tap="downloadCertificate">
            <text class="fa fa-download fa-blue"></text>
          </view>
        </view>

        <!-- 证书2 -->
        <view class="certificate-card">
          <view class="certificate-info">
            <text class="certificate-title">护理质量改进培训证书</text>
            <text class="certificate-type">类型：培训证书</text>
            <text class="certificate-date">颁发：2025.05.22 14:15</text>
            <text class="certificate-number">编号：NQ-2025-0210</text>
            <view class="certificate-badge certificate-badge-green">
              <text class="certificate-badge-text">已获得</text>
            </view>
          </view>
          <view class="certificate-action" @tap="downloadCertificate">
            <text class="fa fa-download fa-blue"></text>
          </view>
        </view>

        <!-- 证书3 -->
        <view class="certificate-card">
          <view class="certificate-info">
            <text class="certificate-title">心肺复苏术培训合格证书</text>
            <text class="certificate-type">类型：技能证书</text>
            <text class="certificate-date">颁发：2025.04.18 16:00</text>
            <text class="certificate-number">编号：CPR-2025-0156</text>
            <view class="certificate-badge certificate-badge-green">
              <text class="certificate-badge-text">已获得</text>
            </view>
          </view>
          <view class="certificate-action" @tap="downloadCertificate">
            <text class="fa fa-download fa-blue"></text>
          </view>
        </view>

        <!-- 证书4 -->
        <view class="certificate-card">
          <view class="certificate-info">
            <text class="certificate-title">ICU专科医师培训证书</text>
            <text class="certificate-type">类型：专科证书</text>
            <text class="certificate-date">颁发：2025.03.25 09:45</text>
            <text class="certificate-number">编号：ICU-2025-0089</text>
            <view class="certificate-badge certificate-badge-green">
              <text class="certificate-badge-text">已获得</text>
            </view>
          </view>
          <view class="certificate-action" @tap="downloadCertificate">
            <text class="fa fa-download fa-blue"></text>
          </view>
        </view>

        <!-- 证书5 - 进行中 -->
        <view class="certificate-card">
          <view class="certificate-info">
            <text class="certificate-title">医疗器械消毒规范培训证书</text>
            <text class="certificate-type">类型：培训证书</text>
            <text class="certificate-date">预计颁发：2025.02.15 10:00</text>
            <text class="certificate-number">完成度：85%</text>
            <view class="certificate-badge certificate-badge-yellow">
              <text class="certificate-badge-text">进行中</text>
            </view>
          </view>
          <view class="certificate-action">
            <text class="fa fa-clock-o"></text>
          </view>
        </view>

        <view class="no-more">
          <text class="no-more-text">没有更多数据了</text>
        </view>
      </scroll-view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      statusBarHeight: 0,
      searchKeyword: "",
    };
  },
  onLoad() {
    const systemInfo = uni.getSystemInfoSync();
    this.statusBarHeight = systemInfo.statusBarHeight || 0;
  },
  methods: {
    goBack() {
      uni.navigateBack();
    },
    goToMessages() {
      uni.navigateTo({
        url: "/pages/messages/messages",
      });
    },
    downloadCertificate() {
      uni.showToast({
        title: "下载功能开发中",
        icon: "none",
      });
    },
    goToHome() {
      uni.navigateTo({
        url: "/pages/home/home",
      });
    },
    goToWorkbench() {
      uni.navigateTo({
        url: "/pages/workbench/workbench",
      });
    },
    goToProfile() {
      uni.navigateTo({
        url: "/pages/profile/profile",
      });
    },
  },
};
</script>

<style scoped>
.page {
  min-height: 100vh;
  background: linear-gradient(to bottom right, #f9fafb, #eff6ff);
  display: flex;
  flex-direction: column;
}

.nav-bar {
  height: 44px;
  background-color: #ffffff;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.nav-left,
.nav-right {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

.nav-left {
  left: 16px;
}

.nav-right {
  right: 16px;
}

.nav-title {
  font-size: 17px;
  font-weight: 600;
  color: #000000;
}

.icon {
  font-size: 20px;
}

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.search-container {
  padding: 12px 16px;
}

.search-box {
  background-color: #f3f4f6;
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-icon {
  font-size: 16px;
  color: #9ca3af;
}

.search-input {
  flex: 1;
  font-size: 14px;
  background-color: transparent;
}

.certificate-list {
  flex: 1;
  padding: 0 16px;
  box-sizing: border-box;
}

.certificate-card {
  background-color: #ffffff;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  border: 1px solid #f3f4f6;
  display: flex;
  justify-content: space-between;
}

.certificate-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.certificate-title {
  font-size: 14px;
  font-weight: 600;
  color: #111827;
  margin-bottom: 4px;
}

.certificate-type,
.certificate-date,
.certificate-number {
  font-size: 12px;
  color: #6b7280;
}

.certificate-date {
  color: #9ca3af;
}

.certificate-badge {
  padding: 4px 8px;
  border-radius: 12px;
  align-self: flex-start;
  margin-top: 8px;
}

.certificate-badge-green {
  background-color: #f0fdf4;
}

.certificate-badge-yellow {
  background-color: #fef3c7;
}

.certificate-badge-text {
  font-size: 12px;
  font-weight: 500;
}

.certificate-badge-green .certificate-badge-text {
  color: #15803d;
}

.certificate-badge-yellow .certificate-badge-text {
  color: #a16207;
}

.certificate-action {
  display: flex;
  align-items: flex-start;
}

.action-icon {
  font-size: 20px;
  color: #2563eb;
}

.action-icon-gray {
  color: #9ca3af;
}

.no-more {
  text-align: center;
  margin-bottom: 16px;
}

.no-more-text {
  font-size: 14px;
  color: #9ca3af;
}

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50px;
  background-color: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-top: 1px solid #f3f4f6;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
}

.tabbar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.tabbar-icon {
  font-size: 22px;
}

.tabbar-text {
  font-size: 12px;
  color: #6b7280;
}

.tabbar-text-active {
  color: #2563eb;
  font-weight: 500;
}
</style>

